<?php
/*------------------------------------------------------ */
//-- 会员登陆注册
//-- Author: iqgmy
/*------------------------------------------------------ */
namespace app\member\controller;
use app\ClientbaseController;
use app\mainadmin\model\SettingsModel;
use think\Db;

class Passport  extends ClientbaseController{
	/*------------------------------------------------------ */
    //-- 优先执行
    /*------------------------------------------------------ */
    public function initialize(){
        parent::initialize();
		$this->assign('sms_fun', settings('sms_fun'));//获取短信配置
        if (empty($this->userInfo) == false){
            return $this->redirect('member/center/index');//已登陆，跳回会员中心
        }
    }
	/*------------------------------------------------------ */
	//-- 登陆
	/*------------------------------------------------------ */
	public function login(){
        $setcolor = new SettingsModel();
        $color = $setcolor->getRows();
		$this->assign('setcolor',$color['systemcolor']);
        $this->assign('title', '会员登录');
        $this->assign('shoplogo',settings('logo'));	
		$this->assign('register_status',settings('register_status'));		
		return $this->fetch('login');
	}
	/*------------------------------------------------------ */
    //-- 注册
    /*------------------------------------------------------ */
    public function register(){    
        $setcolor = new SettingsModel();
        $color = $setcolor->getRows();
		$this->assign('setcolor',$color['systemcolor']);   
		$register_status = settings('register_status');
		if ($register_status != 1){
			return $this->error('暂不开放注册.');
        }
        $share_token = session('share_token');
        $this->assign('title', '会员注册');
        $phone = Db::name('users')->where('user_id',$share_token)->value('mobile');
        $this->assign('shareid', $phone);
        return $this->fetch('register');
    }
    /*------------------------------------------------------ */
    //-- 找回密码
    /*------------------------------------------------------ */
    public function forgetpwd(){
        $this->assign('title', '忘记密码');
        $setcolor = new SettingsModel();
        $color = $setcolor->getRows();
		$this->assign('setcolor',$color['systemcolor']);   
        return $this->fetch('forgetpwd');
    }

    public function getShareUser($val = '',$type = 'token')
    {
        if (empty($val)) return 0;
        $DividendSatus = settings('DividendSatus');
        if ($DividendSatus == 0) return 0;//不开启推荐，不执行
        if ($type == 'token'){
            $pInfo = Db::name('users')->where('token', $val)->find();
        }else{
            $pInfo = Db::name('users')->where('user_id', $val)->find();
        }
        if (empty($pInfo)) return 0;
        if ($pInfo['is_ban'] == 1) {//如果用户被封禁，直接归被封禁用户的上级
            if ($pInfo['pid'] < 1) return 0;
           return $this->getShareUser($pInfo['pid'],'user_id');
        }
        return $pInfo['user_id'];
    }
     /*------------------------------------------------------ */
    //-- 注册协议
    /*------------------------------------------------------ */
    public function regment(){
        $content = preg_replace("/img(.*?)src=[\"|\'](.*?)[\"|\']/",'img class="lazy" width="750" src="/static/mobile/default/images/loading.svg" data-original="$2"', settings('register_agreement'));
        $setcolor = new SettingsModel();
        $color = $setcolor->getRows();
		$this->assign('setcolor',$color['systemcolor']);   
        $this->assign('title','注册协议');
        $this->assign('content', $content);
        return $this->fetch('registerAgreement');
    }

}?>